package com.fangfang.home.adapter;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.common.ui.brvah.BaseMultiItemQuickAdapter;
import com.common.ui.brvah.BaseViewHolder;
import com.common.ui.circleimageview.CircleImageView;
import com.common.utils.DateTimeUtils;
import com.facebook.drawee.view.SimpleDraweeView;
import com.fangfang.R;
import com.fangfang.bean.home.FollowCardBean;
import com.fangfang.bean.home.ItemListBean;
import com.fangfang.bean.home.PictureFollowCardBean;
import com.fangfang.bean.home.SquareCardCollectionBean;
import com.fangfang.bean.home.TextCardBean;
import com.fangfang.bean.home.VideoSmallCardBean;
import com.fangfang.home.views.FontTextView;

import java.util.List;

/**
 * 推荐
 */
public class RecommendLeafAdapter extends BaseMultiItemQuickAdapter<ItemListBean, BaseViewHolder> {

    private Context context;
    public RecommendLeafAdapter(Context context, List data) {
        super(data);
        this.context = context;
        addItemType(ItemListBean.TYPE_ONR, R.layout.video_item_top_leaf_one);
        addItemType(ItemListBean.TYPE_TWO, R.layout.video_item_top_leaf_two);
        addItemType(ItemListBean.TYPE_THREE, R.layout.image_item_leaf_one);
        addItemType(ItemListBean.TYPE_FOUR, R.layout.video_item_leaf_one);
        addItemType(ItemListBean.TYPE_FIVE, R.layout.video_item_leaf_two);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, ItemListBean item) {
        switch (helper.getItemViewType()) {
            case ItemListBean.TYPE_ONR:
                TextCardBean textCardBean = item.getTextCardBean();
                if(textCardBean!=null){
                    helper.setText(R.id.tv_top_title, textCardBean.getText());
                }
                break;
            case ItemListBean.TYPE_TWO:
                SquareCardCollectionBean squareCardCollectionBean = item.getSquareCardCollectionBean();
                if(squareCardCollectionBean!=null){
                    helper.setText(R.id.tv_top_title_two, squareCardCollectionBean.getHeader().getTitle());
                    List<ItemListBean> itemList = squareCardCollectionBean.getItemList();
                    if(itemList!=null && itemList.size()>0){
                        RecyclerView recycleview_top_two = helper.getView(R.id.recycleview_top_two);
                        RecommendLeafAdapter recommendAdapter = new RecommendLeafAdapter(context, itemList);
                        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
                        recycleview_top_two.setLayoutManager(linearLayoutManager);
                        recycleview_top_two.setAdapter(recommendAdapter);
                    }
                }
                break;
            case ItemListBean.TYPE_THREE:
                PictureFollowCardBean pictureFollowCard = item.getPictureFollowCard();
                if(pictureFollowCard!=null){
                    CircleImageView circleImageView = helper.getView(R.id.iv_head_image);
                    circleImageView.setTag(R.id.list_item_head);
                    SimpleDraweeView simpleDraweeView = helper.getView(R.id.simpledraweeview_image);
                    simpleDraweeView.setTag(R.id.list_item_bg);
                    if(pictureFollowCard.getHeader()!=null){
                        helper.loadCircleHeadImageView(context, R.id.iv_head_image, pictureFollowCard.getHeader().getIcon());
                    }
                }
                break;
            case ItemListBean.TYPE_FOUR:
                FollowCardBean followCardBean = item.getFollowCardBean();
                if(followCardBean!=null){
                    CircleImageView circleImageView1 = helper.getView(R.id.iv_head);
                    circleImageView1.setTag(R.id.list_item_head);
                    SimpleDraweeView simpleDraweeView1 = helper.getView(R.id.simpledraweeview);
                    simpleDraweeView1.setTag(R.id.list_item_bg);
                    if(followCardBean.getHeader()!= null){
                        helper.loadCircleHeadImageView(context, R.id.iv_head, followCardBean.getHeader().getIcon());
                        helper.setText(R.id.tv_name, followCardBean.getHeader().getTitle());
                    }
                    if(followCardBean.getContent()!=null){
                        helper.setText(R.id.tv_title, followCardBean.getContent().getTitle());
                        FontTextView fontTextView = helper.getView(R.id.tv_time_duration);
                        fontTextView.setText(DateTimeUtils.format(followCardBean.getContent().getDuration()));
                        helper.setText(R.id.tv_type, "#" + followCardBean.getContent().getCategory());
                        if(followCardBean.getContent().getCover()!=null){
                            helper.setSimpledraweeviewImageURI(R.id.simpledraweeview,followCardBean.getContent().getCover().getFeed());
                        }
                    }
                }
                break;
            case ItemListBean.TYPE_FIVE:
                VideoSmallCardBean videoSmallCardBean = item.getVideoSmallCardBean();
                if(videoSmallCardBean!=null){
                    SimpleDraweeView simpleDraweeView5 = helper.getView(R.id.simpledraweeview5);
                    simpleDraweeView5.setTag(R.id.list_item_bg);
                    FontTextView fontTextView = helper.getView(R.id.tv_time_duration5);
                    fontTextView.setText(DateTimeUtils.format(videoSmallCardBean.getDuration()));
                    if(videoSmallCardBean.getCover()!=null){
                        helper.setSimpledraweeviewImageURI(R.id.simpledraweeview5,videoSmallCardBean.getCover().getFeed());
                    }
                    helper.setText(R.id.tv_title5, videoSmallCardBean.getTitle());
                    helper.setText(R.id.tv_type5, videoSmallCardBean.getCategory());
                    if(videoSmallCardBean.getAuthor()!=null){
                        helper.setText(R.id.tv_name5, videoSmallCardBean.getAuthor().getName());
                    }
                }
                break;
            default:break;
        }
    }
}
